<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class PayController extends Controller
{
    public function goods_pay()
    {
        //分配session信息到模板
        $user_info= session('sign_user_info');
        if(empty($user_info))
        {
            return redirect('login/login_in');
        }else{

            //分配收货地址信息
            $address = DB::table('address')->where(['user_id'=>$user_info['id']])->get();
            //将数据库中暂存的购物车中的信息 添加到购物车列表
            $goods_list = DB::table('shopping_cart')
                ->join('goods','shopping_cart.goods_id','=','goods.goods_id')
                ->join('img','shopping_cart.goods_id','=','img.goods_id')
                ->orderBy('shopping_cart.add_time','desc')
                ->get();

//            $a = [];
//           foreach ($goods_list as $v)
//           {
//               $a[] = (array)$v;
//           }
//            $count = array_column($a,'goods_count');
//            $price = array_column($a,'price');
//
//           print_r($count);

            return view('Home/Pay/goods_pay')->with('user_info',$user_info)->with('address',$address)->with('goods_list',$goods_list);
        }
    }
}
